package com.judian.smart.util;

import android.util.Log;

import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.TextUnderstander;
import com.iflytek.cloud.TextUnderstanderListener;
import com.judian.smart.base.MyApplication;

/**
 * author: Peter
 * date: 2019/10/12 星期六 13:55
 * desc:
 */
public class MyTextUnderstander {
    private static final String TAG = MyTextUnderstander.class.getSimpleName();
    private TextUnderstander mTextUnderstander;

    public MyTextUnderstander() {
        mTextUnderstander = TextUnderstander.createTextUnderstander(MyApplication.getInstance(),new InitListener() {
            @Override
            public void onInit(int code) {
                if (code != ErrorCode.SUCCESS) {
                    Log.d(TAG, "onInit: 初始化文本语义成功");
                }
            }
        });
    }

    /**
     * 文本语义理解
     */
    public void understandText(String text, TextUnderstanderListener textUnderstanderListener){
        mTextUnderstander.understandText(text, textUnderstanderListener);
    }

    /**
     * 回收TextUnderstander资源
     */
    public void destroy(){
        if(mTextUnderstander != null){
            mTextUnderstander.cancel();
            mTextUnderstander.destroy();
        }
    }
}
